package com.colorlight.cloud.grandshow.entity.enumerate;

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;
import com.colorlight.cloud.gateway.api.message.constraint.basics.ienum.EnumTrans;
import com.colorlight.iot.proto.grandshow.entity.GrandShowEntity;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author Demon
 * @description 加密状态
 * @date 21/3/2024  下午6:00
 */
@Getter
public enum EncryptedState implements EnumTrans<GrandShowEntity.EncryptedState, EncryptedState> {
	/**
	 * 默认属性
	 * 加密
	 * 解密
	 */
	StateDefault(GrandShowEntity.EncryptedState.StateDefault),
	Encrypting(GrandShowEntity.EncryptedState.Encrypting),
	Decrypting(GrandShowEntity.EncryptedState.Decrypting),
	;
	private final Integer id;
	private final String name;
	private final GrandShowEntity.EncryptedState encryptedState;
	private static final long serialVersionUID = 987654321987654321L;
	
	EncryptedState(GrandShowEntity.EncryptedState encryptedState) {
		this.id = encryptedState.getNumber();
		this.name = encryptedState.name();
		this.encryptedState = encryptedState;
	}
	
	
	/**
	 * @param encryptedState
	 * @return 对应的类型
	 */
	public static EncryptedState getScheduleTypeStruct(GrandShowEntity.EncryptedState encryptedState) {
		Objects.requireNonNull(encryptedState, "encryptedState can not be null.");
		return Arrays.stream(EncryptedState.values())
				.filter(e -> e.name.equals(encryptedState.name()))
				.findFirst()
				.orElseThrow(() -> new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
	}
	
	
	@Override
	public GrandShowEntity.EncryptedState toProto() {
		return this.encryptedState;
	}
	
	@Override
	public EncryptedState formProto(GrandShowEntity.EncryptedState encryptedState) {
		return getScheduleTypeStruct(encryptedState);
	}

}
